SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].[ArchiveReportSelectMaxDate] @UserId INT
AS 
    BEGIN
        SELECT  MAX(DateCreated)
        FROM    ArchiveReport
        WHERE   DELETED = 0
                AND ( ( @UserId > 0
                        AND UserId = @UserId
                      )
                      OR ( @UserId = 0 )
                    )
    END
GO
